#include<iostream>
#include <list>
#include <string>

using namespace std;
class Student 
{
public:
	Student(string name, int ch, int ma, int e) 
	: _name(name)
    , _chinese(ch)
	, _math(ma)
	, _english(e)
	, _sum(ch + ma + e)
    {
	}

public:
	string _name;   //姓名
	int _chinese;   //语文成绩
	int _math;      //数学成绩
	int _english;   //英语成绩
	int _sum;       //总成绩
};


bool operator>(const Student &p1, const Student &p2)
{
    if(p1._sum > p2._sum)
    {
        return true;
    }
    else if(p1._sum == p2._sum)
    {
        return p1._chinese > p2._chinese;
    }
    else
    {
        return false;
    }
}

#if 0
bool ComparePerson(const Student& p1, const Student& p2)//定义sort排序从大到小
{
    if (p1._sum > p2._sum) 
    {
        return true;
    }
    else if(p1._sum == p2._sum)
    {
    	return  p1._chinese > p2._chinese;
    }
    else
    {
        return false;
    }
}
#endif

#if 1
struct ComparePerson
{
    bool operator()(const Student& p1, const Student& p2)//定义sort排序从大到小
    {
    	if (p1._sum > p2._sum) 
        {
            return true;
    	}
    	else if(p1._sum == p2._sum)
    	{
    		return  p1._chinese > p2._chinese;
    	}
        else
        {
            return false;
        }
    }
};
#endif

void test() 
{
	list<Student> number;

	Student p1("杜雯菲", 88,77,95);
	Student p2("杜蚊分", 67,58,26);
	Student p3("李八八", 95,77,88);
	Student p4("赵二蛋", 86,75,68);
	Student p5("王小牛", 86,46,86);
	Student p6("张小哈", 89,57,68);

	number.push_back(p1);
	number.push_back(p2);
	number.push_back(p3);
	number.push_back(p4);
	number.push_back(p5);
	number.push_back(p6);

	for (list<Student>::iterator it = number.begin(); it != number.end(); ++it) 
    {
		cout << "姓名： " << it->_name
             << " 语文： " << it->_chinese
			 << " 数学： " << it->_math 
             << " 英语： " << it->_english
             << "  总成绩： " << it->_sum
             <<  endl;
	}

	cout << "---------------------------------" << endl;
	/* number.sort(ComparePerson); //排序 */
	/* number.sort(ComparePerson()); //排序 */
    number.sort(std::greater<Student>());
	cout << "排序后" << endl;
	for (list<Student>::iterator it = number.begin(); it != number.end(); ++it)
    {
		cout << "姓名： " << it->_name 
            << " 语文： " << it->_chinese
			<< " 数学： " << it->_math 
            << " 英语： " << it->_english 
            << "  总成绩： " << it->_sum << endl;
	}
}

int main() 
{
	test();
	return 0;
}
